package com.byxy.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.byxy.aspect.MyLog;
import com.byxy.entity.Agency;
import com.byxy.entity.Guide;
import com.byxy.service.GuideService;

public class GuideUpdateAction {

	@Resource
	private GuideService guideService;

	private Integer id; // 序号
	private String name; // 名字
	private String phone; // 电话
	private String qq; // QQ
	private String remark;// 备注
	private Integer sex; // 性别
	private int agencyId; // 旅行社Id

	private List<Agency> agencys;

	private String email; // email

	private Guide guide;

	public Guide getGuide() {
		return guide;
	}

	public void setGuide(Guide guide) {
		this.guide = guide;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public int getAgencyId() {
		return agencyId;
	}

	public void setAgencyId(int agencyId) {
		this.agencyId = agencyId;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public GuideService getGuideService() {
		return guideService;
	}

	public void setGuideService(GuideService guideService) {
		this.guideService = guideService;
	}

	public List<Agency> getAgencys() {
		return agencys;
	}

	public void setAgencys(List<Agency> agencys) {
		this.agencys = agencys;
	}

	@MyLog(desc = "数据更新")
	public String update() {
		if ("POST".equalsIgnoreCase(ServletActionContext.getRequest().getMethod())) {
			Agency agency = new Agency();
			agency.setId(agencyId);
			boolean bSex = sex == 0 ? false : true;
			Guide guide1 = new Guide(id, name, phone, email, bSex, agency, qq, remark);
			guideService.update(guide1);
			return "post";
		} else {
			agencys = guideService.findAgency();
			guide = guideService.getById(id);
			return "get";
		}
	}
}
